﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using LibraryUtility.Data;

namespace WebAppLibrary.GetProvCity
{
    /// <summary>
    /// ClassName:ChinaArea
    /// Auther:Leo.wl
    /// Time:2010-04-15
    /// </summary>
    public class ChinaArea : IArea<ChinaArea>
    {
        private string _name;
        public ChinaArea()
        {
            ;
        }
        private ChinaArea(string name)
        {
            this._name = name;
        }
        #region IArea<ChinaArea> 成员

        public string Name
        {
            get { return this._name; }
        }

        public IList<ChinaArea> GetProv()
        {
            IList<ChinaArea> lists = new List<ChinaArea>();
            string sql = "SELECT DISTINCT province,MAX(areaid) as id FROM pe_city GROUP BY province ORDER BY id ASC";
            SqlDataReader dr = DataAccess.ExcuteQuery(sql);
            while (dr.Read())
                lists.Add(new ChinaArea(dr[0].ToString()));
            dr.Close();
            return lists;
        }

        public IList<ChinaArea> GetCity(string provname)
        {
            IList<ChinaArea> lists = new List<ChinaArea>();
            string sql = "SELECT DISTINCT city,MAX(areaid) as id FROM pe_city WHERE province=@province GROUP BY city ORDER BY id ASC";
            SqlCommand cmd = new SqlCommand(sql);
            cmd.Parameters.Add(DataAccess.CreateSqlParameterVarChar("@province", provname, 50));
            SqlDataReader dr = DataAccess.ExcuteQuery(cmd);
            while (dr.Read())
                lists.Add(new ChinaArea(dr[0].ToString()));
            dr.Close();
            return lists;
        }

        public IList<ChinaArea> GetArea(string cityname)
        {
            IList<ChinaArea> lists = new List<ChinaArea>();
            string sql = "SELECT DISTINCT area,MAX(areaid) as id FROM pe_city WHERE city=@city GROUP BY area ORDER BY id ASC";
            SqlCommand cmd = new SqlCommand(sql);
            cmd.Parameters.Add(DataAccess.CreateSqlParameterVarChar("@city", cityname, 50));
            SqlDataReader dr = DataAccess.ExcuteQuery(cmd);
            while (dr.Read())
                lists.Add(new ChinaArea(dr[0].ToString()));
            dr.Close();
            return lists;
        }

        #endregion
    }
}
